#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: sender.py
# @time: 2021/3/19 15:54
# @desc:
import json

import pika

from utils.mongo_tools import retrieve_one_mongo_value
from views.configs import HISTORY_CLAMP_COLLECTION, MONGO_DATABASE_NAME

MQ_URL = "161.189.87.239"
MQ_PORT = 5672

MQ_ACCOUNT = "admin"
MQ_PASSWORD = "rabbitmq666"

credentials = pika.PlainCredentials(MQ_ACCOUNT, MQ_PASSWORD)
parameters = pika.ConnectionParameters(MQ_URL, MQ_PORT, "/", credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()

channel.queue_declare(queue='stp2gltf', durable=True)

json_data = retrieve_one_mongo_value(number="2021010000000002", database_name=MONGO_DATABASE_NAME, collection_name=HISTORY_CLAMP_COLLECTION)[0]
print(json_data)
channel.basic_publish(exchange='', routing_key='stp2gltf', body=json.dumps(json_data))
print(" [sender] message Sented!")
connection.close()
